<?php
session_start();
cls_General_Forms::code_block_starts('');

//echo 'this is the content of the center';
 #########################################################################  
$blocked = security::head_entry();
  if($blocked){      
  #Form to be loaded in case no post or request has been made		
    if((!isset($_POST['submit']) || !isset($_REQUEST)) && !isset($_SESSION['username'])){
       cls_General_Forms::login_form();  
        #get all the users for display
        
                      // $user_type=admin_functions::get_users();
                       #display the adding form
                      // admin_forms::add_user($user_type);
                     
        }else{
           // echo "<center style='font-size:24pt';>Welcome to SSC Student Information System</center>";
        }
  }else{
      die("<p class='warnings'>This address is temporarily closed due to successive failed login attempts</p>");
  }
#this will be the processing part of posts and requests
if(isset($_POST['submit'])){
    switch($_POST['submit']){

        
            case 'LOGIN':
                    #this will check validity of credentials if  true
                    $profile=admin_functions::check_user_profile($_POST['username'],$_POST['password'],$_POST['profile_id']);  
                        if($profile){                               
                              #this will reset the counter of the ip
                              $_SESSION['page']="Home";  
                              header('location:main.php');
                        }else{
                            die("<p class='warnings'>Invalid user credentials!</p>");
                        }           
                            
                
                break;       
                
           
                  
              case 'Apply Configuration':               
                #this function inserts data to config_assessment  
                admin_functions::enable_assessment($_POST,$_POST['semester']); 
                echo "YOU have successfully configured this system";
                break;
                       
            
                    
               case 'Process Payment':
                        #this will get the payables from collectibles table
                       $data = admin_functions::get_cashier_payments($_POST['student_id'],$_POST['assess_no']);
                       #this will show the requested form
                       $name = sql_functions::select_query("name from cash_profile where student_id='".$_POST['student_id']."'");
                       $name = sql_functions::fetch_to_array($name);
                        cashier_forms::babayaran($data,$name[0]['name'],$_POST['student_id'],$_POST['assess_no']);
                    break; 
               
               case 'Paid':
                    #this will write OR number to collection table and studet ledger
                    admin_functions::pay_all($_POST);
                    $_SESSION['start_or'] = $_SESSION['start_or'] + 1;
                    //cashier_forms::process_print_receipt($_POST['student_id'],$_POST['assess_no']);
                    echo "Successfully updated ledger table";
                    
                    break;
                    
           
                    
                case 'View DAY COLLECTION':
                    #this function view the collection per day
                    if(!isset($_POST['objective'])){
                        $collection = admin_functions::view_collectibles_page($_POST);
                        cashier_forms::collectibles_complete_view($collection,$_POST);
                    }else{
                        $collection = admin_functions::get_all_collection_summary($_POST['month']."-".$_POST['day']."-".$_POST['year']);
                        cashier_forms::general_collection_summary($collection,$_POST['month']."-".$_POST['day']."-".$_POST['year']);
                    }
                    break;
                    
                case 'DOWNLOAD COLLECTION':
                    if(!isset($_POST['type_report'])){
                        #this will download the collection
                         admin_functions::generate_undergrad_collection($_POST);
                    }else{
                        
                        $collection = admin_functions::get_all_collection_summary($_POST['adlaw']);
                        admin_functions::insert_summary_collection($collection,$_POST['adlaw']);
                    }
                    break;
                
                case 'Apply Settings': 
                    #this function will override default settings for syear
                        admin_functions::setting_configure($_POST); 
                    break;  
                
                    
                case 'Change OR':
                    $_SESSION['start_or']=$_POST['start_or'];
                    $_SESSION['end_or']=$_POST['end_or'];
                    echo "Or numbers successfully recorded";
                    break;      
                    
                 case 'Create Account':
                    
                    break;   
                    
                  case 'Update User':
                    #add a user
                    admin_functions::add_edit_delete_users($_POST,"edit");
                    break;   
                                                
    }           
}
if(isset($_REQUEST['action']) && isset($_SESSION['username'])){
    switch($_REQUEST['action']){
          case 'logout':
           // admin_functions::log_out($_SESSION['username'],$_SESSION['password']);
           admin_functions::log_out($_SESSION['username'],$_SESSION['password']);
            session_destroy();
            header("location:main.php");
            break;
            
           case 'settings':
             #this will enable default settings to be changed
               $syear = miscellaneous::school_year();
               admin_forms::settings_config($syear);
                break;
           
           case 'ask':
               if($_REQUEST['page']=="cashier"){
                    if($_REQUEST['spec']=="pay"){
                     #show form for payments processsing
                     if($_SESSION['start_or']>$_SESSION['end_or']){
                         die("<p class='warnings'>No records for OR</p>");
                     }
                      cashier_forms::process_bayad();
                    }elseif($_REQUEST['spec']=="balance"){
                         #shows a form for specifying date
                         #get the month array
                             $month = miscellaneous::buwan();
                             cashier_forms::collectibles_entry($month);
     
                    }elseif($_REQUEST['spec']=="balancegen"){
                        #shows a form for specifying date
                         #get the month array
                             $month = miscellaneous::buwan();
                             cashier_forms::collectibles_entry($month,"general");
                    }elseif($_REQUEST['spec']=="or_entry"){
                        #show the session storage for OR
                        cashier_forms::change_or();
                    }
                   
               }elseif($_REQUEST['page']=="admin"){
                   if($_REQUEST['spec']=="add"){
                       #get all the users for display
                       $user_type=admin_functions::get_users();
                       #display the adding form
                       admin_forms::add_user($user_type);
                   }elseif($_REQUEST['spec']=="view"){
                        #get all the data to view     
                       $data=admin_functions::get_users_profile();
                        admin_forms::view($data);
                   }elseif($_REQUEST['spec']=="delete"){
                       #this will delete the user from user_profile
                       $data=array('username'=>$_REQUEST['username']);
                       admin_functions::add_edit_delete_users($data,"delete");
                   }else{
                        #this will edit the user from user_profile
                       #get all the users for display
                       $user_type=admin_functions::get_users();
                       #get records
                       $records=admin_functions::get_specific_profile($_SESSION['username']);
                       #display the adding form
                       admin_forms::edit_user($user_type,$records);
                   }
               }
               break;
               
          case 'config':
                 if($_REQUEST['page']=="registrar"){
                     
                 }elseif($_REQUEST['page']=="admin"){
                        if($_REQUEST['spec']=="assessment"){
                               #get the assessemtn for option
                               $assessment=admin_functions::get_assessment();
                               #show to forms
                               admin_forms::assessment_names($assessment); 
                        }
                 }
            break;
                     
    }  

}
 ###############################################################################       
cls_General_Forms::code_block_ends();
?>